<template>
  <div>
    <el-card>
      <div slot="header">
        <el-row :gutter="24">
          <el-col :span="12">
            <strong>实验答疑</strong>
          </el-col>
          <!-- <el-col :span="12" class="frx">
            <el-button type="primary" @click="showAdd=true">添加答疑</el-button>
          </el-col> -->
        </el-row>
        <el-row :gutter="24" class="mt_5">
          <el-col :span="6" class="flex_item aic">
            <span class="mr_1">姓名</span>
            <el-input v-model="username" class="fill_x_7"></el-input>
          </el-col>
          <el-col :span="7" class="flex_item aic">
            <span class="mr_1">学校/单位</span>
            <el-input v-model="school" class="fill_x_7"></el-input>
          </el-col>
          <el-col :span="6" class="flex_item aic">
            <span class="mr_1">问题</span>
            <el-input v-model="question" class="fill_x_7"></el-input>
          </el-col>
          <el-col :span="5">
            <el-button type="primary" @click="search">搜索</el-button>
            <el-button @click="reset">重置</el-button>
          </el-col>
        </el-row>
      </div>
      <el-row>
        <el-table :data="source">
          <el-table-column label="姓名" prop="username"></el-table-column>
          <el-table-column label="学校/单位" prop="school"></el-table-column>
          <el-table-column label="实验答疑" prop="question" width="300px"></el-table-column>
          <el-table-column label="创建时间">
            <template slot-scope="scope">{{$parseDate(scope.row.createTime)}}</template>
          </el-table-column>
          <el-table-column label="是否答复" width="100px">
            <template slot-scope="scope">
              <span v-if="scope.row.isAnswer===1">是</span>
              <span v-else>否</span>
            </template>
          </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button size="mini" @click="openDetail(scope.row)">查看</el-button>
              <el-button size="mini" @click="openDelete(scope.row.id)" type="danger">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-row>
      <el-pagination
        :page-size="size"
        :total="total"
        :current-page.sync="page"
        @current-change="loadSource"
      ></el-pagination>
    </el-card>
    <AnwserDetailDialog :visible.sync="showDetail" :id="id" :username="unmae"></AnwserDetailDialog>
    <AddAnwserDialog :visible.sync="showAdd"></AddAnwserDialog>
    <NDeleteDialog :visible.sync="showDelete" title="你确定要删除该答疑？" :delMethods="deleteAnwser"></NDeleteDialog>
  </div>
</template>

<script>
import AnwserDetailDialog from "../../../components/dialog/AnwserDetailDialog.vue";
import AddAnwserDialog from "../../../components/dialog/AddAnwserDialog.vue";
import NDeleteDialog from '../../../components/ndialog/delete/NDeleteDialog.vue';
import Qapi from "../../../api/Question.js";
export default {
  data() {
    return {
      page: 1,
      size: 15,
      username: "",
      school: "",
      question: "",
      total: 15,
      showDetail: false,
      showAdd: false,
      id: 0,
      deleteId:null,
      showDelete:false,
      unmae: "",
      source: []
    };
  },
  components: {
    AnwserDetailDialog,
    AddAnwserDialog,
    NDeleteDialog,
  },
  methods: {
    openDetail(row) {
      this.showDetail = true;
      this.id = row.id;
      this.unmae = row.username;
    },
    addAnwser() {},
    loadParams() {
      return {
        username: this.username,
        school: this.school,
        question: this.question,
        pageNum: this.page,
        pageSize: this.size
      };
    },
    loadSource() {
      this.axios
        .get(Qapi.findByParams, {
          params: this.loadParams()
        })
        .then(res => {
          if (res.data.status === 0) {
            this.source = res.data.data.list;
            this.total = res.data.data.total;
          }
        });
    },
    openDelete(id){
      this.deleteId = id;
      this.showDelete = true;
    },
    reset(){
      this.username = '',
      this.school = '',
      this.question = '',
      this.page = 1;
      this.size = 15;
      this.loadSource();
    },
    search(){
      this.page = 1;
      this.size = 15;
      this.loadSource();
    },
    deleteAnwser(){
      this.axios.delete(Qapi.delete,{params:{id:this.deleteId}}).then(res=>{
        if(res.data.status===0){
          this.loadSource();
        }
      })
    }
  },
  mounted() {
    this.loadSource();
  }
};
</script>

<style>
</style>
